use std::cmp::Ordering;
fn sprintln(_need: &str){
    println!("[SWE] (slh) {}",_need)
}
pub fn guess_num() {
    sprintln("开始猜数字，请键入1～100的整数");
    let target_num =  rand::Rng::gen_range(&mut rand::thread_rng(), 1..101);
    loop{
        let mut _answer = String::new();
        std::io::stdin()
            .read_line(&mut _answer)
            .expect("[SWE] (slh) Error parsing answer.");
        let _answer: u32 = match _answer.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };
        match _answer.cmp(&target_num) {
            Ordering::Less => sprintln("太小了"),
            Ordering::Greater => sprintln("太大了"),
            Ordering::Equal => {
                sprintln("猜对了");
                break;
            }
        }
    }
}